<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="__static/lib/layui-v2.5.5/css/layui.css" media="all">
	<link rel="stylesheet" href="__static/css/public.css" media="all">
	<style>
		.layui-form-pane .layui-form-label {
			width: 90px;
		}
	</style>
</head>
<body>
<div class="layuimini-container">
	<div class="layuimini-main">
		<fieldset class="table-search-fieldset">
			<legend>搜索信息</legend>
			<form class="layui-form layui-form-pane" action="">
				<div class="layui-form-item" style="margin-bottom: 5px;">
					<div class="layui-inline">
						<label class="layui-form-label">退款帐户</label>
						<div class="layui-input-inline">
							<select name="acc_id" lay-search="" autocomplete="off">
								<option value="" >直接选择或搜索选择</option>
								{volist name="acc_list" id="vo"}
									<option value="{$vo.id}" >{$vo.name_id}</option>
								{/volist}
					        </select>
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">端口</label>
						<div class="layui-input-inline">
							<select name="channel_id" lay-search="" autocomplete="off">
								<option value="" >直接选择或搜索选择</option>
								{volist name="channel" id="vo"}
									<option value="{$vo.id}" >{$vo.name}</option>
								{/volist}
					        </select>
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">客户</label>
						<div class="layui-input-inline">
							<select name="customer_id" lay-search="" autocomplete="off">
								<option value="" >直接选择或搜索选择</option>
								{volist name="cu_list" id="vo"}
									<option value="{$vo.id}" >{$vo.name}</option>
								{/volist}
					        </select>
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">媒介</label>
						<div class="layui-input-inline">
							<select name="media_id" lay-search="" autocomplete="off">
								<option value="" >直接选择或搜索选择</option>
								{volist name="media_list" id="vo"}
									<option value="{$vo.id}" >{$vo.username}</option>
								{/volist}
					        </select>
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">申请时间</label>
						<div class="layui-input-inline">
							<input type="text" name="time" id="date" placeholder="请选择时间" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
					</div>
				</div>
			</form>
		</fieldset>
		<table class="layui-hide" id="refundTableId" lay-filter="refundTableFilter"></table>
		<script type="text/html" id="refundtTableBar">
			
			<a style="{{d.status == 1?'display:none':''}}" class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="cashier">出纳</a>
			<a style="{{d.status == 1?'display:none':''}}" class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">驳回</a>
			<a style="{{d.status == 1?'':'display:none'}}" class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="hg">回滚</a>
		</script>
		<script type="text/html" id="statusrefundTable">
			<span onmouseover=get_msg(this) data-msg="{{d.reject}}"  style="color: red;font-weight: bold;{{d.status == -1?'':'display:none;'}}">驳回</span>
			<span  style="color: #03A9F4;font-weight: bold;{{d.status == 0?'':'display:none;'}}">审核中</span>
			<span  style="color: #4CAF50;font-weight: bold;{{d.status == 1?'':'display:none;'}}">完成</span>
		</script>
		<script type="text/html" id="wxmsg">
			<a class="layui-btn layui-btn-xs data-count-edit btn" lay-event="wxmsg">复制</a>
		</script>
	</div>
</div>
<script src="__static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="__static/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="__static/js/clipboard/clipboard.min.js" charset="utf-8"></script>
<script>
function get_msg(obj){
	var str = $(obj).attr('data-msg');
	layer.tips(str,$(obj));
}
	var form,table,laydate
	layui.use(['form', 'table', 'tableSelect', 'laydate'], function () {
		$ = layui.jquery , form = layui.form , table = layui.table , laydate = layui.laydate
		 laydate.render({
		    elem: '#date' //指定元素
			,range: '&'
		  });
		table.render({
			elem: '#refundTableId',
			height: 'full-150',
			id:'get_acc_refunds',
			url: '{:url("account_refund")}?t=json',
			method : 'post',
			toolbar: true,
			totalRow: true,
			cols: [[
				{ field: 'name_id', title: '账户ID',width:140, totalRowText: '合计',fixed: 'left' },
				{ field: 'create_time', title: '申请时间',width:180,fixed: 'left'},
				{ field: 'channel_name', title: '端口' ,width:120},
				
				{ field: 'customer_name', title: '客户名称',width:120},
				{ field: 'account_name', title: '端口/销售/客户',width:220 ,templet:function(d){
					return d.channel_rebate + ' / ' + d.sell_rebates + ' / ' + d.rebate
				}},
				{ field: 'currency', title: '应退帐户币',width:120, totalRow: true},
				{ field: 'amount', title: '退客户金额',width:120, totalRow: true},
				{ field: 'channel_money', title: '端口退款',width:120, totalRow: true},
				{ field: 'profit', title: '公司利润(元)',width:110, totalRow: true},
				{ field: 'sell_profit', title: '销售利润',width:100, totalRow: true },
				{ field: 'status', title: '状态',width:100,toolbar:'#statusrefundTable' },
				{ field: 'send_num', title: '群消息', toolbar: '#wxmsg', width:100 },
				{ field: 'screenshot_url', title: '退款凭证',width:180,templet:function(d){
					return d.screenshot_url?'<img src="'+d.screenshot_url+'">':''
				}},
				{ field: 'audit_proof_url', title: '财务凭证',width:180,templet:function(d){
					return d.audit_proof_url?'<img src="'+d.audit_proof_url+'">':''
				}},
				
				{ field: 'note', title: '备注',width:180},
				{ field: 'media_name', title: '媒介',width:180},
				{ field: 'code', title: '编号',width:180},
				{ title: '操作',fixed: 'right', toolbar: '#refundtTableBar', align: "center",width:130 }
			]],
			
			limit: 30,
			page: true,
			skin: 'line',
		});
		//监听操作栏事件
		table.on('tool(refundTableFilter)', function (obj) {
			var data = obj.data;
			switch (obj.event) {
				case 'cashier':
					get_cashier(data.id);
				break;
				case 'delete':
					get_bohuis(data.id);
				break;
				case 'hg':
					get_huigun(data.id);
				break;
				case 'wxmsg':
					//console.log(data);
					var str12 = '账户：'+data.name_id+' \n退款：'+data.currency+'币';
					new Clipboard('.btn', {
						text: function(trigger) {
							layer.msg('复制成功', {icon: 6});
							return str12;
						}
					});
				break;
			}
			
		});
		//驳回
		function get_bohuis(id){
			layer.prompt({
				  formType: 2,
				  title: '驳回原因',
				  area: ['350px', '150px'] //自定义文本域宽高
				}, function(value, index, elem){
					layer.load(1, { shade : [ 0.5, '#676a6c' ] });
					$.post("{:url('get_buohui_refund')}?t=json",{id:id,reject:value},function(data){
					 	layer.closeAll();
						if (data['code'] == 1) {
							get_apply(data['msg']);
						} else {
							layer.msg(data['msg'], { icon : 5 });
						}
					})
				});
			 
		}
		
		//出纳确认
		function get_cashier(id){
			layer.open({
		        type: 2,
		        title:'出纳确认',
		        area: ['60%', '80%'],
		        fixed: false, //不固定
		        maxmin: true,
		        shadeClose:false,	//点击遮罩后关闭提示框
		        scrollbar:false, //- 是否允许浏览器出现滚动
		        content: "{:url('cashier_audit')}?id="+id 
		    });
		}
		//回滚
		function get_huigun(id){
			layer.confirm('您确认要回滚此条数据吗？', function(index){
				layer.load(1, { shade : [ 0.5, '#676a6c' ] });
				$.post("{:url('get_huigun_refund')}?t=json",{id:id},function(data){
					layer.closeAll();
					if (data['code'] == 1) {
						get_apply(data['msg']);
					} else {
						layer.msg(data['msg'], { icon : 5 });
					}
				})
			});  
		}
		//搜索
		form.on('submit(data-search-btn)', function(data){
			var articleFrom = data.field;
			table.reload('get_acc_refunds', {
			  	url: '{:url("account_refund")}?t=json',
				where:articleFrom
			});
			return false;
		  });
		//监听行单击事件
		table.on('row(refundTableFilter)', function(obj){
			  layer.photos({
				  photos: obj.tr
				  ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
				});
			});
		
		
	});
	//重载数据表
	function get_apply(msg){
		table.reload('get_acc_refunds', {
			  url: '{:url("account_refund")}?t=json',
			});
		layer.msg(msg, {icon: 6});
	}
</script>

</body>
</html>